#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std; 
class Time
{
public:
    Time(int hour, int min, int s, int falg)
        :_hour(hour)
        , _min(min)
        , _s(s)
        , _falg(falg)
    {}
    void Print()
    {
        printf("%02d:%02d:%02d", _hour, _min, _s);
    }
    bool operator==(const Time& d)
    {
        return _hour == d._hour && _min == d._min && _s == d._s;
    }
    void falg(int k)
    {
        _falg = k;
    }
    int Getfalg()
    {
        return _falg;
    }
private:
    int _hour;
    int _min;
    int _s;
    int _falg;
};
int main()
{

    Time* timearr = (Time*)malloc(sizeof(Time) * 60 * 60 * 24);
    int cnt = 0;
    for (int i = 0; i < 24; i++)
    {
        for (int j = 0; j < 60; j++)
        {
            for (int k = 0; k < 60; k++)
            {
                Time Date(i, j, k, 0);
                timearr[cnt] = Date;
                cnt++;
            }
        }
    }
    int k;

    cin >> k;
    for (int i = 0; i < k; i++)
    {
        int h1, h2, m1, m2, s1, s2;
        scanf("%d:%d:%d - %d:%d:%d", &h1, &m1, &s1, &h2, &m2, &s2);
        if(timearr[h1 * 60 * 60 + m1 * 60 + s1].Getfalg()==0)
              timearr[h1 * 60 * 60 + m1 * 60 + s1].falg(1);
        else 
              timearr[h1 * 60 * 60 + m1 * 60 + s1].falg(0);
        if (timearr[h2 * 60 * 60 + m2 * 60 + s2].Getfalg() == 0)
              timearr[h2 * 60 * 60+ m2 * 60 + s2].falg(2);
        else 
              timearr[h2 * 60 * 60 + m2 * 60 + s2].falg(0);

    }
    cnt = 0;
    int fflag = 0;
    while (timearr[cnt].Getfalg() == 0)
    {
        if (cnt == 0)
        {
            timearr[cnt].Print();
            cout << " - ";
            fflag = 1;
        }
        cnt++;
    }
    if(fflag)
    {
        timearr[cnt].Print();
        cout << endl;
    }
    for (int i = cnt+1; i < 24 * 60 * 60-1; i++)
    {
  
        if (timearr[i].Getfalg() == 2)
        {
            timearr[i ].Print();
            cout << " - ";
        }
        if (timearr[i].Getfalg() == 1)
        {
            timearr[i].Print();
            cout << endl;
        }
    }
    if (timearr[24 * 60 * 60 - 1].Getfalg() == 0)
    {
        timearr[24 * 60 * 60 - 1].Print();
    }
    return 0;

}
